﻿using System;
using System.Text;
using CommandLine;

namespace TransformConfig
{
    class Program
    {
        static void Main(string[] args)
        {
            var options = new Options();

            var parser = new CommandLineParser(new CommandLineParserSettings(false, Console.Error));

            if (parser.ParseArguments(args, options))
            {
                Transformation.PerformTransform(options.Source, options.Transform, options.Output);
            }
            else
            {
                Environment.Exit(-1);
            }
        }

    }

    class Options
    {
        [Option("s", null, HelpText = "Path to the source web.config file", Required = true)] public string Source = null;

        [Option("t", null, HelpText = "Path to the transform file", Required = true)] public string Transform = null;

        [Option("o", null, HelpText = "Output destination path of the transform", Required = true)] public string Output = null;

        [HelpOption(HelpText = "Dispaly this help screen.")]
        public string GetUsage()
        {
            var builder = new StringBuilder();
            builder.AppendLine("\nUsage: TransformConfig -Source <source_config> -Transform <transform_file> -Output <output_file>");
            builder.AppendLine();
            builder.AppendLine("s   Path to the source web.config file");
            builder.AppendLine("t   Path to the transform file");
            builder.AppendLine("o   Output destination path of the transform");
            builder.AppendLine();
            builder.AppendLine("E.g. TransformConfig -s web.config -t web.debug.config -o web.output.config");
            builder.AppendLine();
            return builder.ToString();
        }
    }
}
